package com.sunlg.smarthome.ui.environment;

import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.sunlg.smarthome.R;
import com.sunlg.smarthome.base.BaseActivity;
import com.sunlg.smarthome.contract.AirConditionerContract;
import com.sunlg.smarthome.contract.presenter.AirConditionerPresenter;

import butterknife.BindView;

public class AirConditionerActivity extends BaseActivity
        implements View.OnClickListener, AirConditionerContract.View{

    @BindView(R.id.btn_start)
    Button btnStart;
    @BindView(R.id.btn_stop)
    Button btnStop;
    @BindView(R.id.iv_air)
    ImageView ivAir;

    AirConditionerContract.Presenter presenter;

    @Override
    protected int getLayoutResourceId() {
        return R.layout.activity_air_conditioner;
    }

    @Override
    protected void setupToolBar(Toolbar toolbar) {
        super.setupToolBar(toolbar);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle("空调");
        actionBar.setDisplayHomeAsUpEnabled(true);

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                doFinish();
            }
        });
    }

    @Override
    protected void init() {
        presenter = new AirConditionerPresenter();
        presenter.attachView(this);
    }

    @Override
    protected void initView() {

        btnStart.setOnClickListener(this);
        btnStop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.btn_start){
            presenter.startAirConditioner(0);
        }else if(v.getId() == R.id.btn_stop){
            presenter.stopAirConditioner(0);
        }
    }

    @Override
    public void startSuccess() {
        toast("开启成功");
    }

    @Override
    public void stopSuccess() {
        toast("关闭成功");
    }

    @Override
    public void showError(String msg) {
        toast(msg);
    }
}
